<div style="text-align:left; padding:10px;">
In this example you can see a grid with all it's features.<br />
Notice that persons are ordered by groups (Meaning that same order value is ok for different groups)
</div>
{$contents}

{literal}
<div style="text-align:left; padding:10px;">
<h2>Source</h2>

<pre class="code">
&lt;?php
if( $_GET['delete'] &amp;&amp; $item = GridPerson::load( $_GET['delete'] )){
			$item-&gt;delete();
		}
		
		if( $_GET['moveUp'] &amp;&amp; $item = GridPerson::load($_GET['moveUp']) ) {
			$item-&gt;order-&gt;decrease();
		}
		
		if( $_GET['moveDown'] &amp;&amp; $item = GridPerson::load($_GET['moveDown']) ) {
			$item-&gt;order-&gt;increase();
		}
		
		if( $_GET['change'] ){
			$message = array(
				'type' =&gt; 'warning',	
				'message' =&gt; 'Muutmist ei ole!',
			);
		}
		
		DomFgPost::getInstance('advancedGrid')-&gt;store('advancedGrid',array('personsGrid'));

		$post = DomFgPost::getInstance();
		if( $post-&gt;save ) {
			foreach( $post-&gt;order as $id =&gt; $i ) {
				$item = GridPerson::load( $id );
				$item-&gt;order-&gt;setPos( $i );
				$item-&gt;save();
			}
		}
		
		$query = GridPerson::query();
		switch( $post-&gt;personsGrid['orderByField'] ) {
			case 'name': $query-&gt;orderBy('t.lastname, t.firstname '.$post-&gt;personsGrid['orderByDirection']); break;
			case 'age': $query-&gt;orderBy('t.age '.$post-&gt;personsGrid['orderByDirection']); break;
			case 'group': $query-&gt;orderBy('t.group '.$post-&gt;personsGrid['orderByDirection']); break;
			case 'money': $query-&gt;orderBy('t.money '.$post-&gt;personsGrid['orderByDirection']); break;
			case 'spent': $query-&gt;orderBy('t.spent '.$post-&gt;personsGrid['orderByDirection']); break;
			default: $query-&gt;orderBy('t.group, t.order '.$post-&gt;personsGrid['orderByDirection']); break;
		}
		
		$source = new DomArDataSource( $query, 30 );
		
		function handler_name( $person ) {
			return $person['firstname'].' '.$person['lastname'];
		}
		
		function handler_order( $row, $i, $controller ) {
			$field  = array(
				'type' =&gt; 'number',	
				'value' =&gt; $row['order'],
				'name' =&gt; 'order['.$row['id'].']',
			);
			$html = ' 
				&lt;a href="'.$controller-&gt;getUrl('advancedGrid').'&amp;amp;pg='.$_GET['pg'].'&amp;amp;moveUp='.$row['id'].'"&gt;Üles&lt;/a&gt; 
				&lt;a href="'.$controller-&gt;getUrl('advancedGrid').'&amp;amp;pg='.$_GET['pg'].'&amp;amp;moveDown='.$row['id'].'"&gt;Alla&lt;/a&gt; ';
			return DomFg::render( $field ) . $html;
		}
		
		function handler_row( GridPerson $person, $color ) {
			$result = array();
			$result['id'] = $person-&gt;id;
			$result['firstname'] = $person-&gt;firstname;
			$result['lastname'] = $person-&gt;lastname;
			$result['age'] = $person-&gt;age;
			$result['order'] = $person-&gt;order-&gt;pos;
			$result['group'] = $person-&gt;group;
			$result['money'] = $person-&gt;money;
			$result['spent'] = $person-&gt;spent.' ('.round($person-&gt;spent * 100 / $person-&gt;money).'%)';
			return $result;
		}
		
		$panel = array(
			'title' =&gt; 'title',
			'layout' =&gt; 'table',
			'action' =&gt; $this-&gt;getUrl('advancedGrid'),
			'layoutConfig' =&gt; array(
				'columns' =&gt; 1,
			),
			'items' =&gt; array(
				$message,
				array(
					'name' =&gt; 'personsGrid',
					'type' =&gt; 'grid',
					'source' =&gt; $source,
					'link' =&gt; $this-&gt;getUrl('advancedGrid'),
					'rowHandler' =&gt; 'handler_row',
					'rowHandlerArgs' =&gt; array( 'red' ),
					'fields' =&gt; array(
						array('handler' =&gt; 'handler_name', 'title' =&gt; 'Nimi', 'orderByField' =&gt; 'name'),
						array('key' =&gt; 'age', 'title' =&gt; 'Vanus', 'orderByField' =&gt; 'age'),
						array('key' =&gt; 'group', 'title' =&gt; 'Grupp', 'orderByField' =&gt; 'group'),
						array('key' =&gt; 'money', 'title' =&gt; 'Raha', 'orderByField' =&gt; 'money'),
						array('key' =&gt; 'spent', 'title' =&gt; 'Kulutatud', 'orderByField' =&gt; 'spent'),
						array('handler' =&gt; 'handler_order', 'handlerArgs' =&gt; array( $this ), 'title' =&gt; 'Jrk', 'orderByField' =&gt; 'jrk'),
						array('type' =&gt; 'gridButton', 'value' =&gt; 'Muuda', 'link' =&gt; $this-&gt;getUrl('advancedGrid/&amp;amp;change='), 'title' =&gt; 'Valikud','colspan' =&gt; 2),
						array('type' =&gt; 'gridButton', 'value' =&gt; 'Kustuta', 'link' =&gt; $this-&gt;getUrl('advancedGrid/&amp;amp;delete='), 'confirmMessage' =&gt; 'Are you sure?' ),
					),
				),
				array(
					'type' =&gt; 'button',	
					'style' =&gt; 'margin-left:400px;',
					'title' =&gt; 'Salvesta',
					'name' =&gt; 'save',
				),
			),
		);
					
		$this-&gt;view-&gt;contents = DomFg::render( $panel );
?&amp;gt;
</pre>
</div>
{/literal}